package com.yuma.springmcpserver.service;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherToolService {

    @JsonIgnoreProperties(ignoreUnknown = true)
    public record TeacherInfo(@JsonProperty("teacherName") String teacherName,@JsonProperty("teachSubject") String teachSubject) {}

    List<TeacherInfo> teacherInfos = List.of(
            new TeacherInfo("lj","Java"),
            new TeacherInfo("zpy","前端"),
            new TeacherInfo("lkl","Java"),
            new TeacherInfo("rd","数据库"),
            new TeacherInfo("dhl","前端"),
            new TeacherInfo("mhy","Java"),
            new TeacherInfo("wl","Java"));

    @Tool(description = "根据老师姓名，获取专业方向")
    public String getTeachSubject(@ToolParam(description = "老师姓名，必须从以下列表中选择: lj, zpy, lkl, rd, dhl, mhy, wl") String teacherName) {
        if (teacherName == null) {
            return "未检索到当前老师";
        }
        // 清理输入参数
        String trimmedName = teacherName.trim();

        for (TeacherInfo teacherInfo : teacherInfos) {
            if (teacherInfo.teacherName().equalsIgnoreCase(trimmedName)) {
                return teacherInfo.teachSubject();
            }
        }
        return "未检索到当前老师" + trimmedName;
    }
}